package com.ruoyi.web.controller.teachingmaterialgrade;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.LhqTeachingMaterialGrade;
import com.ruoyi.service.ILhqTeachingMaterialGradeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教材等级Controller
 * 
 * @author ruoyi
 * @date 2020-09-08
 */
@Controller
@RequestMapping("/ruoyi/grade")
public class LhqTeachingMaterialGradeController extends BaseController
{
    private String prefix = "ruoyi/grade";

    @Autowired
    private ILhqTeachingMaterialGradeService lhqTeachingMaterialGradeService;

    @RequiresPermissions("ruoyi:grade:view")
    @GetMapping()
    public String grade()
    {
        return prefix + "/grade";
    }

    /**
     * 查询教材等级列表
     */
    @RequiresPermissions("ruoyi:grade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LhqTeachingMaterialGrade lhqTeachingMaterialGrade)
    {
        startPage();
        List<LhqTeachingMaterialGrade> list = lhqTeachingMaterialGradeService.selectLhqTeachingMaterialGradeList(lhqTeachingMaterialGrade);
        return getDataTable(list);
    }

    /**
     * 导出教材等级列表
     */
    @RequiresPermissions("ruoyi:grade:export")
    @Log(title = "教材等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LhqTeachingMaterialGrade lhqTeachingMaterialGrade)
    {
        List<LhqTeachingMaterialGrade> list = lhqTeachingMaterialGradeService.selectLhqTeachingMaterialGradeList(lhqTeachingMaterialGrade);
        ExcelUtil<LhqTeachingMaterialGrade> util = new ExcelUtil<LhqTeachingMaterialGrade>(LhqTeachingMaterialGrade.class);
        return util.exportExcel(list, "grade");
    }

    /**
     * 新增教材等级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教材等级
     */
    @RequiresPermissions("ruoyi:grade:add")
    @Log(title = "教材等级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LhqTeachingMaterialGrade lhqTeachingMaterialGrade)
    {
        return toAjax(lhqTeachingMaterialGradeService.insertLhqTeachingMaterialGrade(lhqTeachingMaterialGrade));
    }

    /**
     * 修改教材等级
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqTeachingMaterialGrade lhqTeachingMaterialGrade = lhqTeachingMaterialGradeService.selectLhqTeachingMaterialGradeById(id);
        mmap.put("lhqTeachingMaterialGrade", lhqTeachingMaterialGrade);
        return prefix + "/edit";
    }

    /**
     * 修改保存教材等级
     */
    @RequiresPermissions("ruoyi:grade:edit")
    @Log(title = "教材等级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LhqTeachingMaterialGrade lhqTeachingMaterialGrade)
    {
        return toAjax(lhqTeachingMaterialGradeService.updateLhqTeachingMaterialGrade(lhqTeachingMaterialGrade));
    }

    /**
     * 删除教材等级
     */
    @RequiresPermissions("ruoyi:grade:remove")
    @Log(title = "教材等级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lhqTeachingMaterialGradeService.deleteLhqTeachingMaterialGradeByIds(ids));
    }
}
